import { createRouter, createWebHashHistory } from 'vue-router';
import { routes } from './routes';
import { useTitle } from '@vueuse/core';
import { useAppStore } from '@/store/modules/app'; 
import NProgress from "nprogress";
import "nprogress/nprogress.css";

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

const webTitle = useTitle();

NProgress.configure({
  showSpinner: false,
  easing: "ease",
  speed: 500,
  minimum: 0.1,
  parent: "#app"
});


router.beforeEach((to, from, next) => {
  const { hideProgress, title } = to.meta;
  if(!hideProgress){
    NProgress.start();
  }
  webTitle.value = title;
  const appStore = useAppStore();
  appStore.setTitle(title)
  next();
})

router.afterEach((to, from) => {
  const { hideProgress } = to.meta;
  if(!hideProgress){
    NProgress.done();
  }
})

export {
  router
}